/*
 * @Author: 梁青春
 * @Date: 2025-11-03 10:55:17
 * @LastEditTime: 2025-11-07 09:26:58
 * @LastEditors: 梁青春
 */
/**
 * @Description: 病区管理Mock数据
 * @Author: 梁青春
 * @Date: 2025-11-03 11:00:00
 */

// 模拟病区数据
const wardList = [
  {
    id: 1,
    wardName: '一病区',
    wardLocation: '南楼5层',
    relatedDepartments: '神经内科、心脏内科',
    memberCount: 5,
    roomCount: 10,
    bedCount: 30,
    createTime: '2024-01-15 09:30:00',
    updateTime: '2024-01-15 09:30:00',
    status: 1, // 1-正常 0-停用
    description: '主要负责神经内科和心脏内科患者的住院治疗'
  },
  {
    id: 2,
    wardName: '二病区',
    wardLocation: '南楼6层',
    relatedDepartments: '呼吸内科、消化内科',
    memberCount: 6,
    roomCount: 12,
    bedCount: 36,
    createTime: '2024-01-16 10:00:00',
    updateTime: '2024-01-16 10:00:00',
    status: 1,
    description: '主要负责呼吸内科和消化内科患者的住院治疗'
  },
  {
    id: 3,
    wardName: '三病区',
    wardLocation: '北楼3层',
    relatedDepartments: '骨科、外科',
    memberCount: 8,
    roomCount: 15,
    bedCount: 45,
    createTime: '2024-01-17 14:20:00',
    updateTime: '2024-01-17 14:20:00',
    status: 1,
    description: '主要负责骨科和外科患者的住院治疗'
  },
  {
    id: 4,
    wardName: '四病区',
    wardLocation: '北楼4层',
    relatedDepartments: '妇产科、儿科',
    memberCount: 7,
    roomCount: 14,
    bedCount: 42,
    createTime: '2024-01-18 16:45:00',
    updateTime: '2024-01-18 16:45:00',
    status: 1,
    description: '主要负责妇产科和儿科患者的住院治疗'
  },
  {
    id: 5,
    wardName: 'ICU病区',
    wardLocation: '东楼2层',
    relatedDepartments: '重症医学科',
    memberCount: 12,
    roomCount: 8,
    bedCount: 20,
    createTime: '2024-01-19 08:15:00',
    updateTime: '2024-01-19 08:15:00',
    status: 1,
    description: '重症监护病区，负责危重患者的监护治疗'
  }
]

// 科室列表数据
const departmentList = [
  { id: 1, name: '神经内科', code: 'SJNK' },
  { id: 2, name: '心脏内科', code: 'XZNK' },
  { id: 3, name: '呼吸内科', code: 'HXNK' },
  { id: 4, name: '消化内科', code: 'XHNK' },
  { id: 5, name: '骨科', code: 'GK' },
  { id: 6, name: '外科', code: 'WK' },
  { id: 7, name: '妇产科', code: 'FCK' },
  { id: 8, name: '儿科', code: 'EK' },
  { id: 9, name: '重症医学科', code: 'ZSYXK' },
  { id: 10, name: '急诊科', code: 'JZK' }
]

// 收费项目数据
const chargeItemList = [
  {
    id: 1,
    name: '静脉输液费(含输液器)',
    category: '治疗费',
    unitPrice: 26,
    unit: '次',
    selected: false
  },
  {
    id: 2,
    name: '小输液(含输液器以下1升)',
    category: '治疗费',
    unitPrice: 26,
    unit: '次',
    selected: false
  },
  { id: 3, name: '微泵输液', category: '治疗费', unitPrice: 26, unit: '次', selected: false },
  {
    id: 4,
    name: '静脉输液费(含输液器以下1升)',
    category: '治疗费',
    unitPrice: 26,
    unit: '次',
    selected: false
  },
  { id: 5, name: '微量输液', category: '治疗费', unitPrice: 26, unit: '次', selected: false },
  { id: 6, name: '肌肉注射', category: '治疗费', unitPrice: 15, unit: '次', selected: false },
  { id: 7, name: '皮下注射', category: '治疗费', unitPrice: 12, unit: '次', selected: false },
  { id: 8, name: '静脉注射', category: '治疗费', unitPrice: 18, unit: '次', selected: false },
  { id: 9, name: '床位费', category: '床位费', unitPrice: 50, unit: '天', selected: false },
  { id: 10, name: '护理费', category: '护理费', unitPrice: 30, unit: '天', selected: false },
  { id: 11, name: '监护费', category: '监护费', unitPrice: 80, unit: '天', selected: false },
  { id: 12, name: '氧气费', category: '治疗费', unitPrice: 20, unit: '小时', selected: false }
]

// 成员列表数据
const memberList = [
  { id: 1, name: '张郡', department: '神经内科', position: '主治医师', phone: '13800138001' },
  { id: 2, name: '王文丽', department: '心脏内科', position: '副主任医师', phone: '13800138002' },
  { id: 3, name: '陆亚男', department: '呼吸内科', position: '住院医师', phone: '13800138003' },
  { id: 4, name: '王静', department: '消化内科', position: '主治医师', phone: '13800138004' },
  { id: 5, name: '高炜', department: '骨科', position: '副主任医师', phone: '13800138005' },
  { id: 6, name: '段京美', department: '外科', position: '主任医师', phone: '13800138006' },
  { id: 7, name: '刘树彦', department: '妇产科', position: '主治医师', phone: '13800138007' },
  { id: 8, name: '余亚辉', department: '儿科', position: '住院医师', phone: '13800138008' },
  { id: 9, name: '马爱芹', department: '重症医学科', position: '副主任医师', phone: '13800138009' },
  { id: 10, name: '高梦楠', department: '急诊科', position: '主治医师', phone: '13800138010' },
  { id: 11, name: '李安', department: '神经内科', position: '住院医师', phone: '13800138011' }
]

// 病区统计数据
const wardStatistics = {
  totalWards: 5,
  totalRooms: 59,
  totalBeds: 173,
  totalMembers: 38,
  occupancyRate: 85.5, // 床位使用率
  averageStay: 7.2 // 平均住院天数
}

// Mock API响应
export const mockWardApi = {
  // 获取病区列表
  getWardList: (params = {}) => {
    const { pageNum = 1, pageSize = 10, wardName = '', status = '' } = params

    let filteredList = [...wardList]

    // 按病区名称筛选
    if (wardName) {
      filteredList = filteredList.filter(item => item.wardName.includes(wardName))
    }

    // 按状态筛选
    if (status !== '') {
      filteredList = filteredList.filter(item => item.status === parseInt(status))
    }

    // 分页处理
    const start = (pageNum - 1) * pageSize
    const end = start + pageSize
    const pagedList = filteredList.slice(start, end)

    return {
      code: 200,
      message: '获取成功',
      data: {
        list: pagedList,
        total: filteredList.length,
        pageNum: parseInt(pageNum),
        pageSize: parseInt(pageSize)
      }
    }
  },

  // 获取病区详情
  getWardDetail: id => {
    const ward = wardList.find(item => item.id === parseInt(id))

    if (ward) {
      return {
        code: 200,
        message: '获取成功',
        data: ward
      }
    } else {
      return {
        code: 404,
        message: '病区不存在',
        data: null
      }
    }
  },

  // 新增病区
  addWard: data => {
    const newWard = {
      id: Math.max(...wardList.map(item => item.id)) + 1,
      ...data,
      createTime: new Date().toLocaleString('zh-CN'),
      updateTime: new Date().toLocaleString('zh-CN'),
      status: 1
    }

    wardList.push(newWard)

    return {
      code: 200,
      message: '新增成功',
      data: newWard
    }
  },

  // 编辑病区
  updateWard: data => {
    const index = wardList.findIndex(item => item.id === data.id)

    if (index !== -1) {
      wardList[index] = {
        ...wardList[index],
        ...data,
        updateTime: new Date().toLocaleString('zh-CN')
      }

      return {
        code: 200,
        message: '编辑成功',
        data: wardList[index]
      }
    } else {
      return {
        code: 404,
        message: '病区不存在',
        data: null
      }
    }
  },

  // 删除病区
  deleteWard: id => {
    const index = wardList.findIndex(item => item.id === parseInt(id))

    if (index !== -1) {
      const deletedWard = wardList.splice(index, 1)[0]

      return {
        code: 200,
        message: '删除成功',
        data: deletedWard
      }
    } else {
      return {
        code: 404,
        message: '病区不存在',
        data: null
      }
    }
  },

  // 批量删除病区
  batchDeleteWard: ids => {
    const deletedWards = []

    ids.forEach(id => {
      const index = wardList.findIndex(item => item.id === parseInt(id))
      if (index !== -1) {
        deletedWards.push(wardList.splice(index, 1)[0])
      }
    })

    return {
      code: 200,
      message: `成功删除${deletedWards.length}个病区`,
      data: deletedWards
    }
  },

  // 获取科室列表
  getDepartmentList: () => {
    return {
      code: 200,
      message: '获取成功',
      data: departmentList
    }
  },

  // 检查病区名称
  checkWardName: (name, id = null) => {
    const exists = wardList.some(item => item.wardName === name && item.id !== parseInt(id))

    return {
      code: 200,
      message: '检查完成',
      data: {
        exists,
        message: exists ? '病区名称已存在' : '病区名称可用'
      }
    }
  },

  // 获取成员列表
  listUserByDepts: (params = {}) => {
    const { keyword = '' } = params

    let filteredList = [...memberList]

    // 按关键词筛选（姓名、科室、职位）
    if (keyword) {
      filteredList = filteredList.filter(
        item => item.name.includes(keyword) || item.department.includes(keyword) || item.position.includes(keyword)
      )
    }

    return {
      code: 200,
      message: '获取成功',
      data: filteredList
    }
  },

  // 获取病区统计信息
  getWardStatistics: () => {
    return {
      code: 200,
      message: '获取成功',
      data: wardStatistics
    }
  },

  // 获取收费项目列表
  getChargeItemList: (params = {}) => {
    const { keyword = '' } = params

    let filteredList = [...chargeItemList]

    // 按关键词筛选（项目名称、类别）
    if (keyword) {
      filteredList = filteredList.filter(item => item.name.includes(keyword) || item.category.includes(keyword))
    }

    return {
      code: 200,
      message: '获取成功',
      data: filteredList
    }
  }
}

export default mockWardApi
